$:.unshift File.join(File.dirname(__FILE__), "..","..","m")

require 'test/unit'
require 'zpop'

class ZPOPTest < Test::Unit::TestCase

	def setup
	  @url  = 'mail.server.com'
		@port = 110
		@user = 'user.name'
	end

	def teardown
	end

	def test_url?
		assert(ZPOP.url?(@url))
		assert_equal(false,ZPOP.url?('http://'+@url))
		assert_equal(false,ZPOP.url?('ftp://'+@url))
		assert_equal(false,ZPOP.url?(@url+' foo'))
	end

	def test_port?
	  assert(ZPOP.port?(@port))
	  assert(ZPOP.port?(1))
	  assert(ZPOP.port?(65535))
		assert_equal(false,ZPOP.port?(0))
		assert_equal(false,ZPOP.port?(-@port))
		assert_equal(false,ZPOP.port?(67000))		
	end

	def test_email?
		assert(ZPOP.email?(@user+'@'+@url))
		assert_equal(false,ZPOP.email?(@user+'@'+'http://'+@url))
		assert_equal(false,ZPOP.email?(@user+'@'+'ftp://'+@url))
		assert_equal(false,ZPOP.email?(@user+'@'+@url+' foo'))
		assert_equal(false,ZPOP.email?(@user+'@@'+'http://'+@url))
		assert_equal(false,ZPOP.email?(@user+'@'+'ftp:@//'+@url))
		assert_equal(false,ZPOP.email?(@user+'@'+@url+' @foo'))
	end
	
	def test_initialize
		assert_instance_of(ZPOP,ZPOP.new(@url,@port))
		assert_raise(RuntimeError){ZPOP.new(@url+' foo',@port)}
		assert_raise(RuntimeErorr){ZPOP.new(@url,0)}
	end

	def test_apop
		z = ZPOP.new(@url,@port)
		assert_equal(true,z.apop?)
		z.apop=false
		assert_equal(false,z.apop?)
	end

#	def test_start
#	end

end
